/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.javanile.chess.stone;

/**
 *
 * @author totalinnovation
 */
public class Less {
    static String square(int s) {
	return ""+(char)(97+s%8)+(char)(56-s/8);
    }
    static String square(byte s) {
	return ""+(char)(97+s%8)+(char)(56-s/8);
    }
    static public String move(int f, int t) {
	return square(f)+square(t);
    }
    static public String move(int[] m) {
	return square(m[0])+square(m[1]);
    }
    static String piece(int p) {
	String o="";
	if(p>0){o="w";}else{o="b";p=(int)(-p);}
	if(p==1)o+="p";
	if(p==2)o+="n";
	if(p==3)o+="b";
	if(p==4)o+="r";
	if(p==5)o+="q";
	if(p==6)o+="k";
	return o;
    }
    static String piece(Piece x) {
	int p = x.value();
	String o="";
	if(p>0){o="w";}else{o="b";p=(int)(-p);}
	if(p==1)o+="p";
	if(p==2)o+="n";
	if(p==3)o+="b";
	if(p==4)o+="r";
	if(p==5)o+="q";
	if(p==6)o+="k";
	return o;
    }
    static String ul_symbol(int p) {
	String o="";
	int c = p;
	if(p>0){}else{p=(int)(-p);}
	if(p==1)o+="p";
	if(p==2)o+="n";
	if(p==3)o+="b";
	if(p==4)o+="r";
	if(p==5)o+="q";
	if(p==6)o+="k";
	if(c<0)	{o=o.toLowerCase();}
	    else{o=o.toUpperCase();}
	if(p==0)o=".";
	return o;
    }
    static public String board(int[] b) {
	String out = "";
	for(int i=0;i<64;i++) {
	    if ((i%8==0)&&(i>0)) out+="\n";
	    out+=ul_symbol(b[i])+" ";
	}
	return out;
    }
    static public int square(char c, char r) {
	return (int)(((int)c-97)+(56-(int)r)*8);
    }
    static public int square(int c, int r) {
	return (int)((c-97)+(56-r)*8);
    }
    static public int[] move(String m) {
	int f = square(m.charAt(0),m.charAt(1));
	int t = square(m.charAt(2),m.charAt(3));
	return new int[] {f,t};
    }
    static public String variant(int[][] path, int level) {
	String p = "";
	for (int i=0;i<level;i++) {
	    p+=Less.move(path[i])+" ";
	}
	return p;
    }
    static public String fixlen(String s, int l) {
	if (s.length()>l) {
	    return s.substring(0,l-3)+"...";
	}
	while(s.length()<l)s+=" ";
	return s;
    }
}
